package com.cddata;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import com.cddata.util.DBOperation;

@SuppressWarnings("serial")
public class FileDataProgress extends JFrame implements Runnable{
	public FileDataProgress() {
		super(DBOperation.getHelperBean().getFileName());
		JPanel panel = new JPanel ();
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		label = new JLabel();
		progressBar = new JProgressBar(0,DBOperation.getHelperBean().getLines());
		progressBar.setStringPainted(true);
		panel.add(label);
		panel.add( progressBar);
		add(panel);
		setAlwaysOnTop(true);
		setBounds(DBOperation.getHelperBean().getMainWindowWidth()/2+100, DBOperation.getHelperBean().getMainWindowHieght()/2+100, 300, 75); // Size
		setVisible(true);
	}

	public void run() {
		try{
			if( DBOperation.getHelperBean().isProcessFinished()) {
				setVisible(false);
			}
			label.setText(DBOperation.getHelperBean().getLabelText());
			progressBar.setValue(DBOperation.getHelperBean().getInsertedLines());
			progressBar.paintImmediately(progressBar.getVisibleRect());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void setMax( int aMax) {
		this.progressBar.setMaximum(aMax);
	}

	JProgressBar progressBar = null;
	JLabel label = null;
}
